package com.room.rest;

import com.cyh.dao.SysConstant;
import com.cyh.dao.dto.RoomDto;
import com.cyh.dao.dto.SolicitDmtDto;
import com.cyh.dao.entity.Reserve;
import com.cyh.dao.entity.Room;
import com.cyh.dao.entity.SolicitDmt;
import com.cyh.dao.entity.SolicitNew;
import com.room.core.annotation.LoginUser;
import com.room.core.dto.UserInfo;
import com.room.core.util.NumberUtil;
import com.room.core.util.R;
import com.room.dto.WxLoginInfo;
import com.room.service.ManageService;
import com.room.service.RoomService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/wx/manage")
public class ManageController {

    @Autowired
    private ManageService manageService;

    /**
     * 添加自习室
     *
     * @param userInfo
     * @return
     */
    @PostMapping("addRoom")
    public R addRoom(@LoginUser UserInfo userInfo,
                     @RequestBody RoomDto dto) {
        manageService.addRoom(dto);
        return R.success();
    }

    /**
     * 获取指定时间段下的教室
     *
     * @param userInfo
     * @return
     */
    @PostMapping("getTimeIntervalList")
    public R getTimeIntervalList(@LoginUser UserInfo userInfo,
                                 @RequestParam Long timeInterval) {
        List<RoomDto> list = manageService.getTimeIntervalList(timeInterval);
        return R.success(list);
    }

    /**
     * 获取需要绑定的数据
     * @param userInfo
     * @param timeInterval
     * @return
     */
    @PostMapping("getNeedTimeIntervalList")
    public R getNeedTimeIntervalList(@LoginUser UserInfo userInfo,
                                 @RequestParam Integer timeInterval) {
        List<RoomDto> list = manageService.getNeedTimeIntervalList(timeInterval);
        return R.success(list);
    }

    @PostMapping("bindTimeIntervalRoom")
    public R bindTimeIntervalRoom(@LoginUser UserInfo userInfo,
                                     @RequestParam Integer timeInterval,
                                    @RequestParam Long roomId) {
        manageService.bindTimeIntervalRoom(timeInterval,roomId);
        return R.success();
    }

    /**
     * 教室时间段解绑
     *
     * @param userInfo
     * @param timeInterval 时间段
     * @param id           教室id
     * @return
     */
    @PostMapping("removeTimeInterval")
    public R removeTimeInterval(@LoginUser UserInfo userInfo,
                                @RequestParam Integer timeInterval,
                                @RequestParam Long id) {
        manageService.removeTimeInterval(timeInterval, id);
        return R.success();
    }


    /**
     * 教室时间段绑定
     *
     * @param userInfo
     * @param timeInterval
     * @return
     */
    @PostMapping("setTimeInterval")
    public R setTimeInterval(@LoginUser UserInfo userInfo,
                             @RequestParam Long timeInterval) {
        List<RoomDto> list = manageService.getTimeIntervalList(timeInterval);
        return R.success(list);
    }

    /**
     * 获取多媒体待审核列表
     * @param userInfo
     * @return
     */
    @PostMapping("getSolicitDmtList")
    public R getSolicitDmtList(@LoginUser UserInfo userInfo) {
        List<SolicitDmtDto> list = manageService.getSolicitDmtList();
        return R.success(list);
    }

    /**
     * 获取多媒体待审核详情
     * @param userInfo
     * @return
     */
    @PostMapping("getSolicitDmtDetail")
    public R getSolicitDmtDetail(@LoginUser UserInfo userInfo,
                                 @RequestParam Long id) {
        SolicitDmtDto detail = manageService.getSolicitDmtDetail(id);
        return R.success(detail);
    }


    /**
     * 审核多媒体教室
     * @param userInfo
     * @param id
     * @param agreeIs 1同意，2拒绝
     * @return
     */
    @PostMapping("reviewSolicitDmt")
    public R reviewSolicitDmt(@LoginUser UserInfo userInfo,
                                 @RequestParam Long id,
                              @RequestParam Integer agreeIs) {
        manageService.reviewSolicitDmt(id, agreeIs);
        return R.success();
    }


    @PostMapping("getSolicitNew")
    public R getSolicitNew(@LoginUser UserInfo userInfo) {
        return R.success(manageService.getSolicitNew());
    }

    /**
     * 审核新教室
     * @param userInfo
     * @param state
     * @return
     */
    @PostMapping("reviewSolicitNew")
    public R reviewSolicitNew(@LoginUser UserInfo userInfo,
                           @RequestParam Integer state) {
        manageService.reviewSolicitNew(state);
        return R.success();
    }



}
